/* ----------------------------------------------------------------------- *
 *                                                                         *
 *                Ecole des Mines de Nantes - OSE OSM 2012                 *
 *                                                                         *
 * ----------------------------------------------------------------------- * 
 *
 * File:     utils/Coordinates.h
 * Version:  1.0
 * Created:  20:09 01/05/2012
 * Modified: 20:09 01/05/2012
 * Author:   Léopold Houdin
 * Description:
 *
 * ----------------------------------------------------------------------- */

#ifndef COORDINATES_H
#define COORDINATES_H

#include <limits>

namespace pud
{

  class UnsignedCoordinates
  {
  public:
    /**
     * Default constructor.
     * Constructs coordinates in the invalid state.
     */
    UnsignedCoordinates()
    {
      this->x = this->y = std::numeric_limits< unsigned >::max();
    }

    /**
     *	Parameterized constructor.
     *	Constructs a coordinate with the given parameters.
     */
    UnsignedCoordinates( unsigned xVal, unsigned yVal )
    {
      this->x = xVal;
      this->y = yVal;
    }

    /**
     *	Equality operator.
     *	Succeeds if the given coordinate is structurally equal to this coordinate.
     */
    bool
    operator==( const UnsignedCoordinates& right ) const
    {
      return x == right.x && y == right.y;
    }

    /**
     *	Inequality operator.
     *	Succeeds if the given coordinate is structurally not equal to this coordinate.
     */
    bool
    operator!=( const UnsignedCoordinates& right ) const
    {
      return !( *this == right );
    }

    /**
     *	Lower operator.
     *	Succeeds if the given coordinate is structurally greater than this coordinate.
     */
    bool
    operator<( const UnsignedCoordinates& right ) const
    {
      if ( x != right.x )
        return x < right.x;
      return y < right.y;
    }

    /**
     *	Checks whether this coordinate is in the invalid state.
     *	It does not check for invalid coordinates.
     */
    bool
    isValid() const
    {
      return x != std::numeric_limits< unsigned >::max() && y != std::numeric_limits< unsigned >::max();
    }

    unsigned x, y;

  };
}

#endif // COORDINATES_H

